//
//  LZLoginTextFieldView.m
//  laziz_Consumer
//
//  Created by ZhaoDongBo on 2016/10/25.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZLoginTextFieldView.h"
#import "Masonry.h"
#import "BlocksKit+UIKit.h"
#import "LZTextField.h"
#import "LZPopAlertView.h"
#import "GVUserDefaults+LZLogin.h"

@interface LZLoginTextFieldView ()<UITextFieldDelegate>
@property (nonatomic, strong) LZPopAlertView *passwordRecoveryPopView;
@end

@implementation LZLoginTextFieldView

- (instancetype)initWithPage:(LZLOGIN_TF_TYPE_PAGE)page {
    
    self = [super init];
    if (self) {
        
        self.page = page;

        [self setup];
    }
    return self;
}

- (void)setup {
    
    switch (self.page) {
        case LZLOGIN_TF_TYPE_PAGE_REGISTER_PHONE:
        {
            [self pageRegisterByPhone];
        }
            break;
        case LZLOGIN_TF_TYPE_PAGE_REGISTER_MAIL:
        {
            [self pageRegisterByMail];
        }
            break;
        case LZLOGIN_TF_TYPE_PAGE_FASTLOGIN:
        {
            [self pageFastLogin];
        }
            break;
        case LZLOGIN_TF_TYPE_PAGE_PHONELOGIN:
        {
            [self pagePhoneLogin];
        }
            break;
        case LZLOGIN_TF_TYPE_PAGE_MAILLOGIN:
        {
            [self pageMailLogin];
        }
            break;
        case LZLOGIN_TF_TYPE_PAGE_PASSWORD:
        {
            [self pageInputPassword];
        }
            break;
            
        case LZLOGIN_TF_TYPE_PAGE_FINDPASSWORD_PHONE:
        {
            [self pageFindPasswordByPhone];
        }
            break;
            
        case LZLOGIN_TF_TYPE_PAGE_FINDPASSWORD_MAIL:
        {
            [self pageFindPasswordByMail];
        }
            break;
    }
}

//注册---手机号注册
- (void)pageRegisterByPhone {
    
    WS(weakSelf);
    GET_SCREEN_SCALE(scale);
    
    [self addSubview:self.areaCodeTextField];
    [self addSubview:self.markImageView];
    [self addSubview:self.mobileNumTextField];
    [self addSubview:self.verificCodeButton];
    [self addSubview:self.countdownLabel];
    [self addSubview:self.line1];
    
    [self addSubview:self.verificCodeTextField];
    [self addSubview:self.line2];
    
    [self addSubview:self.passwordTextField];
    [self addSubview:self.showPWbutton];
    [self addSubview:self.line3];
    
    [self addSubview:self.agreementButton];
    [self.agreementButton addSubview:self.selectButton];
    [self.agreementButton addSubview:self.agreementLabel];
    
    self.mobileNumTextField.keyboardType  = UIKeyboardTypePhonePad;
    self.mobileNumTextField.placeholder = LZLocalizedString(@"login_mobile", @"");// 手机号登录提示
    [self.mobileNumTextField setValue:UIColorFromRGB(0xcccccc, 1) forKeyPath:@"_placeholderLabel.textColor"];
    
    self.passwordTextField.placeholder  = LZLocalizedString(@"password_text", @"");//@"password (Min. 6 characters)";
    [self.passwordTextField setValue:UIColorFromRGB(0xcccccc, 1) forKeyPath:@"_placeholderLabel.textColor"];

    self.verificCodeTextField.placeholder   = LZLocalizedString(@"login_verifi_code", @"");//@"Verification Code";
    [self.verificCodeTextField setValue:UIColorFromRGB(0xcccccc, 1) forKeyPath:@"_placeholderLabel.textColor"];

    [self.areaCodeTextField makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.leading.mas_equalTo(30.0*scale);
        make.width.mas_equalTo(55.0*scale);
        make.height.mas_equalTo(55.0*scale);
    }];
    
    [self.markImageView makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.areaCodeTextField.mas_centerY);
        make.leading.mas_equalTo(weakSelf.areaCodeTextField.mas_trailing).with.offset(5);
        make.size.mas_equalTo(CGSizeMake(6.5, 13));
    }];
    
    [self.mobileNumTextField makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.leading.mas_equalTo(weakSelf.areaCodeTextField.mas_trailing).with.offset(10);
        make.trailing.mas_equalTo(weakSelf.verificCodeButton.mas_leading).with.offset(-10);
        make.height.mas_equalTo(55.0*scale);
    }];
    
    [self.verificCodeButton makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(-26.0*scale);
        make.size.mas_equalTo(CGSizeMake(40, 40));
        make.centerY.mas_equalTo(weakSelf.areaCodeTextField.centerY);
    }];
    
    [self.countdownLabel makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(-30.0*scale);
        make.size.mas_equalTo(CGSizeMake(32, 19));
        make.centerY.mas_equalTo(weakSelf.areaCodeTextField.centerY);
    }];
    
    [self.line1 makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.areaCodeTextField.mas_bottom);
        make.leading.mas_equalTo(30.0*scale);
        make.trailing.mas_equalTo(-30.0*scale);
        make.height.mas_equalTo(1);
    }];
    
    [self.verificCodeTextField makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.line1.mas_bottom);
        make.leading.mas_equalTo(30.0*scale);
        make.trailing.mas_equalTo(-30.0*scale);
        make.height.mas_equalTo(55.0*scale);
    }];
    
    [self.line2 makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.verificCodeTextField.mas_bottom);
        make.leading.mas_equalTo(30.0*scale);
        make.trailing.mas_equalTo(-30.0*scale);
        make.height.mas_equalTo(1);
    }];
    
    [self.passwordTextField makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.line2.mas_bottom);
        make.leading.mas_equalTo(30.0*scale);
        make.trailing.mas_equalTo(-30.0*scale);
        make.height.mas_equalTo(55.0*scale);
    }];
    
    [self.showPWbutton makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(-20.0*scale);
        make.centerY.mas_equalTo(weakSelf.passwordTextField.centerY);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
    
    [self.line3 makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.passwordTextField.mas_bottom);
        make.leading.mas_equalTo(30.0*scale);
        make.trailing.mas_equalTo(-30.0*scale);
        make.height.mas_equalTo(1);
    }];
    
    [self.agreementButton makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.line3.mas_bottom);
        make.leading.mas_equalTo(30.0*scale);
        make.trailing.mas_equalTo(-30.0*scale);
        make.height.mas_equalTo(46);
    }];
    
    [self.selectButton makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(12*scale);
        make.size.mas_equalTo(CGSizeMake(16, 16));
        make.leading.mas_equalTo(0);
    }];
    
    [self.agreementLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.leading.mas_equalTo(weakSelf.selectButton.mas_trailing).with.offset(10*scale);
        make.trailing.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
    }];
}

//注册---邮箱注册
- (void)pageRegisterByMail {
    
    WS(weakSelf);
    GET_SCREEN_SCALE(scale);
    
    [self addSubview:self.mobileNumTextField];
    [self addSubview:self.line1];
    
    [self addSubview:self.passwordTextField];
    [self addSubview:self.showPWbutton];
    [self addSubview:self.line2];
    
    [self addSubview:self.agreementButton];
    
    [self.agreementButton addSubview:self.selectButton];
    [self.agreementButton addSubview:self.agreementLabel];
    
    self.mobileNumTextField.placeholder = LZLocalizedString(@"login_email", nil);// 邮箱提示
    [self.mobileNumTextField setValue:UIColorFromRGB(0xcccccc, 1) forKeyPath:@"_placeholderLabel.textColor"];
    
    self.passwordTextField.placeholder  = LZLocalizedString(@"password_text", @"");//@"password (Min. 6 characters)";
    [self.passwordTextField setValue:UIColorFromRGB(0xcccccc, 1) forKeyPath:@"_placeholderLabel.textColor"];
    
    [self.mobileNumTextField makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.leading.mas_equalTo(30.0*scale);
        make.trailing.mas_equalTo(-26.0*scale);
        make.height.mas_equalTo(55.0*scale);
    }];
    
    [self.line1 makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.mobileNumTextField.mas_bottom);
        make.leading.mas_equalTo(30.0*scale);
        make.trailing.mas_equalTo(-30.0*scale);
        make.height.mas_equalTo(1);
    }];
    
    [self.passwordTextField makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.line1.mas_bottom);
        make.leading.mas_equalTo(30.0*scale);
        make.trailing.mas_equalTo(-30.0*scale);
        make.height.mas_equalTo(55.0*scale);
    }];
    
    [self.line2 makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.passwordTextField.mas_bottom);
        make.leading.mas_equalTo(30.0*scale);
        make.trailing.mas_equalTo(-30.0*scale);
        make.height.mas_equalTo(1);
    }];
    
    [self.showPWbutton makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(-20.0*scale);
        make.centerY.mas_equalTo(weakSelf.passwordTextField.centerY);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
    
    [self.agreementButton makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.line2.mas_bottom);
        make.leading.mas_equalTo(30.0*scale);
        make.trailing.mas_equalTo(-30.0*scale);
        make.height.mas_equalTo(46);
    }];
    
    [self.selectButton makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(12*scale);
        make.size.mas_equalTo(CGSizeMake(16, 16));
        make.leading.mas_equalTo(0);
    }];
    
    [self.agreementLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.leading.mas_equalTo(weakSelf.selectButton.mas_trailing).with.offset(10*scale);
        make.trailing.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
    }];
}

//账号密码登录 -- 手机号登录
- (void)pagePhoneLogin {
    
    WS(weakSelf);
    GET_SCREEN_SCALE(scale);
    
    [self addSubview:self.areaCodeTextField];
    [self addSubview:self.markImageView];
    [self addSubview:self.mobileNumTextField];
    [self addSubview:self.line1];
    [self addSubview:self.passwordTextField];
    [self addSubview:self.showPWbutton];
    
    self.mobileNumTextField.keyboardType  = UIKeyboardTypePhonePad;
    self.mobileNumTextField.placeholder = LZLocalizedString(@"login_mobile", @"");// 手机号登录提示
    [self.mobileNumTextField setValue:UIColorFromRGB(0xcccccc, 1) forKeyPath:@"_placeholderLabel.textColor"];
    
    self.passwordTextField.placeholder  = LZLocalizedString(@"login_password", @""); //@"Password";
    [self.passwordTextField setValue:UIColorFromRGB(0xcccccc, 1) forKeyPath:@"_placeholderLabel.textColor"];

    [self.areaCodeTextField makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.leading.mas_equalTo(30.0*scale);
        make.width.mas_equalTo(55.0*scale);
        make.height.mas_equalTo(55.0*scale);
    }];
    
    [self.markImageView makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.areaCodeTextField.mas_centerY);
        make.leading.mas_equalTo(weakSelf.areaCodeTextField.mas_trailing).with.offset(5);
        make.size.mas_equalTo(CGSizeMake(6.5, 13));
    }];
    
    [self.mobileNumTextField makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.leading.mas_equalTo(weakSelf.markImageView.mas_trailing).with.offset(10);
        make.trailing.mas_equalTo(-30*scale);
        make.height.mas_equalTo(55.0*scale);
    }];
    
    [self.line1 makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.mobileNumTextField.mas_bottom);
        make.leading.mas_equalTo(30.0*scale);
        make.trailing.mas_equalTo(-30.0*scale);
        make.height.mas_equalTo(1);
    }];
    
    [self.passwordTextField makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.line1.mas_bottom);
        make.leading.mas_equalTo(30.0*scale);
        make.trailing.mas_equalTo(-30.0*scale);
        make.height.mas_equalTo(55.0*scale);
    }];
    
    [self.showPWbutton makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(-20.0*scale);
        make.centerY.mas_equalTo(weakSelf.passwordTextField.centerY);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
}

//账号密码登录 -- 邮箱登录
- (void)pageMailLogin {
    
    WS(weakSelf);
    GET_SCREEN_SCALE(scale);
    
    [self addSubview:self.mobileNumTextField];
    [self addSubview:self.line1];
    [self addSubview:self.passwordTextField];
    [self addSubview:self.showPWbutton];
    
    self.mobileNumTextField.placeholder = LZLocalizedString(@"login_email", nil);// 邮箱登录提示
    [self.mobileNumTextField setValue:UIColorFromRGB(0xcccccc, 1) forKeyPath:@"_placeholderLabel.textColor"];
    
    self.passwordTextField.placeholder  = LZLocalizedString(@"login_password", @""); //@"Password";
    [self.passwordTextField setValue:UIColorFromRGB(0xcccccc, 1) forKeyPath:@"_placeholderLabel.textColor"];

    [self.mobileNumTextField makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.leading.mas_equalTo(30.0*scale);
        make.trailing.mas_equalTo(-30*scale);
        make.height.mas_equalTo(55.0*scale);
    }];
    
    [self.line1 makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.mobileNumTextField.mas_bottom);
        make.leading.mas_equalTo(30.0*scale);
        make.trailing.mas_equalTo(-30.0*scale);
        make.height.mas_equalTo(1);
    }];
    
    [self.passwordTextField makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.line1.mas_bottom);
        make.leading.mas_equalTo(30.0*scale);
        make.trailing.mas_equalTo(-30.0*scale);
        make.height.mas_equalTo(55.0*scale);
    }];
    
    [self.showPWbutton makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(-20.0*scale);
        make.centerY.mas_equalTo(weakSelf.passwordTextField.centerY);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
}

//手机验证码登录
- (void)pageFastLogin {
    
    WS(weakSelf);
    GET_SCREEN_SCALE(scale);
    
    [self addSubview:self.areaCodeTextField];
    [self addSubview:self.markImageView];
    [self addSubview:self.mobileNumTextField];
    [self addSubview:self.verificCodeButton];
    [self addSubview:self.countdownLabel];
    [self addSubview:self.line1];
    [self addSubview:self.verificCodeTextField];
    
    self.mobileNumTextField.keyboardType  = UIKeyboardTypePhonePad;
    self.mobileNumTextField.placeholder = LZLocalizedString(@"login_mobile", @"");// 手机号登录提示
    [self.mobileNumTextField setValue:UIColorFromRGB(0xcccccc, 1) forKeyPath:@"_placeholderLabel.textColor"];
    
    self.verificCodeTextField.placeholder   = LZLocalizedString(@"login_verifi_code", @"");//@"Verification Code";
    [self.verificCodeTextField setValue:UIColorFromRGB(0xcccccc, 1) forKeyPath:@"_placeholderLabel.textColor"];

    [self.areaCodeTextField makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.leading.mas_equalTo(30.0*scale);
        make.width.mas_equalTo(55.0*scale);
        make.height.mas_equalTo(55.0*scale);
    }];
    
    [self.markImageView makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.areaCodeTextField.mas_centerY);
        make.leading.mas_equalTo(weakSelf.areaCodeTextField.mas_trailing).with.offset(5);
        make.size.mas_equalTo(CGSizeMake(6.5, 13));
    }];
    
    [self.mobileNumTextField makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.leading.mas_equalTo(weakSelf.markImageView.mas_trailing).with.offset(10);
        make.trailing.mas_equalTo(weakSelf.verificCodeButton.mas_leading).with.offset(-10);
        make.height.mas_equalTo(55.0*scale);
    }];
    
    [self.verificCodeButton makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(-26.0*scale);
        make.size.mas_equalTo(CGSizeMake(40, 40));
        make.centerY.mas_equalTo(weakSelf.areaCodeTextField.centerY);
    }];
    
    [self.countdownLabel makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(-30.0*scale);
        make.size.mas_equalTo(CGSizeMake(32, 19));
        make.centerY.mas_equalTo(weakSelf.areaCodeTextField.centerY);
    }];
    
    [self.line1 makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.areaCodeTextField.mas_bottom);
        make.leading.mas_equalTo(30.0*scale);
        make.trailing.mas_equalTo(-30.0*scale);
        make.height.mas_equalTo(1);
    }];
    
    [self.verificCodeTextField makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.line1.mas_bottom);
        make.leading.mas_equalTo(30.0*scale);
        make.trailing.mas_equalTo(-30.0*scale);
        make.height.mas_equalTo(55.0*scale);
    }];
}

// 找回密码--手机号找回
- (void)pageFindPasswordByPhone {
    WS(weakSelf);
    GET_SCREEN_SCALE(scale);
    
    [self addSubview:self.areaCodeTextField];
    [self addSubview:self.markImageView];
    [self addSubview:self.mobileNumTextField];
    [self addSubview:self.verificCodeButton];
    [self addSubview:self.countdownLabel];
    [self addSubview:self.line1];
    [self addSubview:self.verificCodeTextField];
    
    self.mobileNumTextField.keyboardType  = UIKeyboardTypePhonePad;
    self.mobileNumTextField.placeholder = LZLocalizedString(@"login_mobile", @"");// 手机号登录提示
    [self.mobileNumTextField setValue:UIColorFromRGB(0xcccccc, 1) forKeyPath:@"_placeholderLabel.textColor"];

    self.verificCodeTextField.placeholder   = LZLocalizedString(@"login_verifi_code", @"");//@"Verification Code";
    [self.verificCodeTextField setValue:UIColorFromRGB(0xcccccc, 1) forKeyPath:@"_placeholderLabel.textColor"];

    [self.areaCodeTextField makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.leading.mas_equalTo(30.0*scale);
        make.width.mas_equalTo(55.0*scale);
        make.height.mas_equalTo(55.0*scale);
    }];
    
    [self.markImageView makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.areaCodeTextField.mas_centerY);
        make.leading.mas_equalTo(weakSelf.areaCodeTextField.mas_trailing).with.offset(5);
        make.size.mas_equalTo(CGSizeMake(6.5, 13));
    }];
    
    [self.mobileNumTextField makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.leading.mas_equalTo(weakSelf.markImageView.mas_trailing).with.offset(10);
        make.trailing.mas_equalTo(weakSelf.verificCodeButton.mas_leading).with.offset(-10);
        make.height.mas_equalTo(55.0*scale);
    }];
    
    [self.verificCodeButton makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(-26.0*scale);
        make.size.mas_equalTo(CGSizeMake(40, 40));
        make.centerY.mas_equalTo(weakSelf.areaCodeTextField.centerY);
    }];
    
    [self.countdownLabel makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(-30.0*scale);
        make.size.mas_equalTo(CGSizeMake(32, 19));
        make.centerY.mas_equalTo(weakSelf.areaCodeTextField.centerY);
    }];
    
    [self.line1 makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.areaCodeTextField.mas_bottom);
        make.leading.mas_equalTo(30.0*scale);
        make.trailing.mas_equalTo(-30.0*scale);
        make.height.mas_equalTo(1);
    }];
    
    [self.verificCodeTextField makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.line1.mas_bottom);
        make.leading.mas_equalTo(30.0*scale);
        make.trailing.mas_equalTo(-30.0*scale);
        make.height.mas_equalTo(55.0*scale);
    }];
}

// 找回密码--邮箱找回
- (void)pageFindPasswordByMail {
    
    WS(weakSelf);
    GET_SCREEN_SCALE(scale);
    
    [self addSubview:self.mobileNumTextField];
    [self addSubview:self.verificCodeButton];
    [self addSubview:self.countdownLabel];
    [self addSubview:self.line1];
    [self addSubview:self.verificCodeTextField];
    
    self.mobileNumTextField.placeholder = LZLocalizedString(@"login_email", nil);// 邮箱登录提示  ---- e-mail
    [self.mobileNumTextField setValue:UIColorFromRGB(0xcccccc, 1) forKeyPath:@"_placeholderLabel.textColor"];

    self.verificCodeTextField.placeholder   = LZLocalizedString(@"find_password_email_verification", nil);//@"e-Mail verification code"
    [self.verificCodeTextField setValue:UIColorFromRGB(0xcccccc, 1) forKeyPath:@"_placeholderLabel.textColor"];

    [self.mobileNumTextField makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.leading.mas_equalTo(30.0*scale);
        make.trailing.mas_equalTo(weakSelf.verificCodeButton.mas_leading).with.offset(-10);
        make.height.mas_equalTo(55.0*scale);
    }];
    
    [self.verificCodeButton makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(-26.0*scale);
        make.size.mas_equalTo(CGSizeMake(40, 40));
        make.centerY.mas_equalTo(weakSelf.mobileNumTextField.centerY);
    }];
    
    [self.countdownLabel makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(-30.0*scale);
        make.size.mas_equalTo(CGSizeMake(32, 19));
        make.centerY.mas_equalTo(weakSelf.mobileNumTextField.centerY);
    }];
    
    [self.line1 makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.mobileNumTextField.mas_bottom);
        make.leading.mas_equalTo(30.0*scale);
        make.trailing.mas_equalTo(-30.0*scale);
        make.height.mas_equalTo(1);
    }];
    
    [self.verificCodeTextField makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.line1.mas_bottom);
        make.leading.mas_equalTo(30.0*scale);
        make.trailing.mas_equalTo(-30.0*scale);
        make.height.mas_equalTo(55.0*scale);
    }];
}

- (void)pageInputPassword {
    
    WS(weakSelf);
    GET_SCREEN_SCALE(scale);
    
    [self addSubview:self.passwordTextField];
    [self addSubview:self.showPWbutton];
    [self addSubview:self.line1];
    
    self.passwordTextField.placeholder  = LZLocalizedString(@"enter_new_password", @"");//@"Enter new password";
    [self.passwordTextField setValue:UIColorFromRGB(0xcccccc, 1) forKeyPath:@"_placeholderLabel.textColor"];

    [self.passwordTextField makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.leading.mas_equalTo(30.0*scale);
        make.trailing.mas_equalTo(-30.0*scale);
        make.height.mas_equalTo(55.0*scale);
    }];
    
    [self.showPWbutton makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(-20.0*scale);
        make.centerY.mas_equalTo(weakSelf.passwordTextField.centerY);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
    
    [self.line1 makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(30.0*scale);
        make.trailing.mas_equalTo(-30.0*scale);
        make.height.mas_equalTo(1);
        make.bottom.mas_equalTo(0);
    }];
}

#pragma mark -
#pragma mark event
- (void)serviceBtnAction:(UIButton *)btn
{
    btn.selected = !btn.selected;
    if (self.clickAgreementButtonBlock) {
        self.clickAgreementButtonBlock(btn.isSelected);
    }
}

- (void)showPasswordRecoveryPopView
{
    BOOL firstIn = ![[[NSUserDefaults standardUserDefaults] objectForKey:@"password_recovery"] boolValue];
    if (firstIn) {
        [self addSubview:self.passwordRecoveryPopView];
        [self.passwordRecoveryPopView loadText:LZLocalizedString(@"password_recovery", nil) anchor:CGPointMake(self.showPWbutton.frame.origin.x + self.showPWbutton.frame.size.width/2, self.showPWbutton.frame.origin.y + 8)];
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"password_recovery"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
   
}

- (void)hiddenPasswordRecoveryPopView
{
    if (_passwordRecoveryPopView) {
        self.passwordRecoveryPopView.hidden = YES;
        [self.passwordRecoveryPopView removeFromSuperview];
        _passwordRecoveryPopView = nil;
    }
}

- (void)clickAreaCodeTextFieldAction {
    if (self.clickAreaCodeTextFieldBlock) {
        self.clickAreaCodeTextFieldBlock(self.areaCodeTextField);
    }
}
     
#pragma mark - UITextFieldDelegate
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    [self hiddenPasswordRecoveryPopView];
    return YES;
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    
    if (textField.tag == 100) {
        NSInteger strLength = textField.text.length - range.length + string.length;
        if (strLength < 1 || strLength > 5) {
            return NO;
        }
    }
    else if (textField.tag == 200) {
        
        NSInteger strLength = textField.text.length - range.length + string.length;
        
        if (self.page == LZLOGIN_TF_TYPE_PAGE_PHONELOGIN || self.page == LZLOGIN_TF_TYPE_PAGE_MAILLOGIN) {
            if (strLength > 254) {
                return NO;
            }
        }
        else if (self.page == LZLOGIN_TF_TYPE_PAGE_FASTLOGIN ||
                 self.page == LZLOGIN_TF_TYPE_PAGE_REGISTER_PHONE ||
                 self.page == LZLOGIN_TF_TYPE_PAGE_FINDPASSWORD_PHONE ) {
            
            if (strLength > 0) {
                [_verificCodeButton setImage:[UIImage imageNamed:@"lz_getverification_icon_hd"] forState:UIControlStateNormal];
            }
            else {
                [_verificCodeButton setImage:[UIImage imageNamed:@"lz_getverification_icon"] forState:UIControlStateNormal];
            }
            
            if (strLength > 20) {
                return NO;
            }
        }
    }
    return YES;
}

#pragma mark - setter/getter

- (UILabel *)areaCodeTextField {
    
    if (_areaCodeTextField == nil) {
        
        GET_SCREEN_SCALE(scale);
        
        _areaCodeTextField = [[UILabel alloc] init];
        _areaCodeTextField.text             = [GVUserDefaults standardUserDefaults].loginAreaCode?:@"+973";
        _areaCodeTextField.textAlignment    = NSTextAlignmentLeft;
        _areaCodeTextField.font             = [UIFont systemFontOfSize:17.0*scale];
        
        _areaCodeTextField.userInteractionEnabled = YES;
        [_areaCodeTextField setTintColor:UIColorFromRGB(0xff7a21, 1)];
        [_areaCodeTextField setTextColor:UIColorFromRGB(0xffffff, 1)];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickAreaCodeTextFieldAction)];
        tap.numberOfTapsRequired = 1;
        [_areaCodeTextField addGestureRecognizer:tap];
    }
    
    return _areaCodeTextField;
}

- (UIImageView *)markImageView {

    if (_markImageView == nil) {
        _markImageView = [[UIImageView alloc] init];
        if ([[LZLanguageManager shareInstance] getLanguageType] == LanguageType_Ar) {
            _markImageView.image = [UIImage imageNamed:@"lz_login_areamark_image_ar"];
        } else {
            _markImageView.image = [UIImage imageNamed:@"lz_login_areamark_image_en"];
        }
    }
    
    return _markImageView;
}

- (UITextField *)mobileNumTextField {
    
    if (_mobileNumTextField == nil) {
    
        GET_SCREEN_SCALE(scale);
        
        _mobileNumTextField = [[UITextField alloc] init];
        _mobileNumTextField.textAlignment = NSTextAlignmentCenter;
        _mobileNumTextField.delegate      = self;
        _mobileNumTextField.tag           = 200;
        _mobileNumTextField.font          = [UIFont systemFontOfSize:17.0*scale];
        [_mobileNumTextField setTextColor:UIColorFromRGB(0xffffff, 1)];
        [_mobileNumTextField setTintColor:UIColorFromRGB(0xff7a21, 1)];
    }
    
    return _mobileNumTextField;
}

- (UIButton *)verificCodeButton {
    
    if (_verificCodeButton == nil) {
        _verificCodeButton = [[UIButton alloc] init];
        _verificCodeButton.tag = LZLOGIN_TF_BUTTON_TAG_VERIFICCODE;
        [_verificCodeButton setImage:[UIImage imageNamed:@"lz_getverification_icon"] forState:UIControlStateNormal];
        
        WS(weakSelf);
        [_verificCodeButton bk_addEventHandler:^(UIButton * sender) {
            
            if (weakSelf.buttonAction_TF_Block) {
                weakSelf.buttonAction_TF_Block(LZLOGIN_TF_BUTTON_TAG_VERIFICCODE);
            }
            
        } forControlEvents:UIControlEventTouchUpInside];
    }
    
    return _verificCodeButton;
}

- (UILabel *)countdownLabel {

    if (_countdownLabel == nil) {
        _countdownLabel = [[UILabel alloc] init];
        _countdownLabel.textColor           = UIColorFromRGB(0xcccccc, 1);
        _countdownLabel.text                = @"60s";
        _countdownLabel.font                = [UIFont systemFontOfSize:14];
        _countdownLabel.layer.masksToBounds = YES;
        _countdownLabel.layer.cornerRadius  = 2.5;
        _countdownLabel.layer.borderWidth   = 1;
        _countdownLabel.layer.borderColor   = UIColorFromRGB(0xcccccc, 1).CGColor;
        _countdownLabel.hidden              = YES;
        _countdownLabel.textAlignment       = NSTextAlignmentCenter;
    }
    
    return _countdownLabel;
}

- (UIView *)line1 {
    
    if (_line1 == nil) {
        _line1 = [[UIView alloc] init];
        _line1.backgroundColor = UIColorFromRGB(0x8f9091, 1);
    }
    
    return _line1;
}

- (UITextField *)verificCodeTextField {
    
    if (_verificCodeTextField == nil) {
        
        GET_SCREEN_SCALE(scale);
        
        _verificCodeTextField = [[UITextField alloc] init];
        _verificCodeTextField.textAlignment = NSTextAlignmentCenter;
        _verificCodeTextField.delegate      = self;
        _verificCodeTextField.tag           = 300;
        _verificCodeTextField.font          = [UIFont systemFontOfSize:17.0*scale];
        _verificCodeTextField.keyboardType  = UIKeyboardTypeNumberPad;
        [_verificCodeTextField setTextColor:UIColorFromRGB(0xffffff, 1)]; //文字颜色
        [_verificCodeTextField setTintColor:UIColorFromRGB(0xff7a21, 1)]; //光标颜色
    }
    
    return _verificCodeTextField;
}

- (UIView *)line2 {
   
    if (_line2 == nil) {
        _line2 = [[UIView alloc] init];
        _line2.backgroundColor = UIColorFromRGB(0x8f9091, 1);
    }
    
    return _line2;
}

- (UITextField *)passwordTextField {
    
    if (_passwordTextField == nil) {
        
        GET_SCREEN_SCALE(scale);
        
        _passwordTextField = [[LZTextField alloc] init];
        _passwordTextField.textAlignment    = NSTextAlignmentCenter;
        _passwordTextField.secureTextEntry  = YES;
        _passwordTextField.font             = [UIFont systemFontOfSize:17.0*scale];
        [_passwordTextField setTextColor:UIColorFromRGB(0xffffff, 1)];
        [_passwordTextField setTintColor:UIColorFromRGB(0xff7a21, 1)];
    }
    
    return _passwordTextField;
}

- (UIButton *)showPWbutton {
    
    if (_showPWbutton == nil) {

        WS(weakSelf);
        
        _showPWbutton = [[UIButton alloc] init];
        _showPWbutton.tag = LZLOGIN_TF_BUTTON_TAG_SHOWPASSWORD;
        
        if (self.page == LZLOGIN_TF_TYPE_PAGE_PHONELOGIN || self.page == LZLOGIN_TF_TYPE_PAGE_MAILLOGIN) { //忘记密码
            [_showPWbutton setImage:[UIImage imageNamed:@"lz_forgotpassword_icon"] forState:UIControlStateNormal];
        
            [_showPWbutton bk_addEventHandler:^(UIButton * sender) {
                
                if (weakSelf.buttonAction_TF_Block) {
                    weakSelf.buttonAction_TF_Block(LZLOGIN_TF_BUTTON_TAG_SHOWPASSWORD);
                    [weakSelf hiddenPasswordRecoveryPopView];
                }
                
            } forControlEvents:UIControlEventTouchUpInside];
        }
        else { //显示和隐藏 密码
            [_showPWbutton setImage:[UIImage imageNamed:@"lz_hidepassword_icon"] forState:UIControlStateNormal];
            [_showPWbutton setImage:[UIImage imageNamed:@"lz_showpassword_icon"] forState:UIControlStateSelected];
            _showPWbutton.selected = NO;
            [_showPWbutton bk_addEventHandler:^(UIButton * sender) {
                
                if (weakSelf.page != LZLOGIN_TF_TYPE_PAGE_PHONELOGIN) {
                    if (sender.selected) {
                        sender.selected = NO;
                        weakSelf.passwordTextField.secureTextEntry = YES;   //隐藏密码
                    }
                    else {
                        sender.selected = YES;
                        weakSelf.passwordTextField.secureTextEntry = NO;    //显示密码
                    }
                }
                
            } forControlEvents:UIControlEventTouchUpInside];
        }
    }
    
    return _showPWbutton;
}

- (UIView *)line3 {
    
    if (_line3 == nil) {
        _line3 = [[UIView alloc] init];
        _line3.backgroundColor = UIColorFromRGB(0x8f9091, 1);
    }
    
    return _line3;
}

- (UIButton *)agreementButton {

    if (_agreementButton == nil) {
        _agreementButton = [[UIButton alloc] init];
        _agreementButton.tag = LZLOGIN_TF_BUTTON_TAG_AGREEMENT;
        
        WS(weakSelf);
        [_agreementButton bk_addEventHandler:^(UIButton * sender) {
            
            if (weakSelf.buttonAction_TF_Block) {
                weakSelf.buttonAction_TF_Block(LZLOGIN_TF_BUTTON_TAG_AGREEMENT);
            }
            
        } forControlEvents:UIControlEventTouchUpInside];
    }
    
    return _agreementButton;
}

- (UIButton *)selectButton {

    if (_selectButton == nil) {
        _selectButton = [[UIButton alloc] init];
        _selectButton.selected = YES;
        [_selectButton setImage:[UIImage imageNamed:@"lz_selectbutton_icon"]
                       forState:UIControlStateSelected];
        [_selectButton setImage:[UIImage imageNamed:@"lz_normalbutton_icon"]
                       forState:UIControlStateNormal];
        [_selectButton addTarget:self action:@selector(serviceBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    return _selectButton;
}

- (UILabel *)agreementLabel {

    if (_agreementLabel == nil) {
        _agreementLabel = [[UILabel alloc] init];
        _agreementLabel.numberOfLines = 0;
        _agreementLabel.textColor = UIColorFromRGB(0xcccccc, 1);
        GET_SCREEN_SCALE(scale);
        _agreementLabel.font = [UIFont systemFontOfSize:14.0*scale];
        
        NSString *strStart = LZLocalizedString(@"register_termsofservice", @"");
        NSString *strEnd = LZLocalizedString(@"terms_of_service", nil);
        NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@ \" %@ \"",strStart,strEnd]];
        [attStr addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xcccccc, 1) range:NSMakeRange(0, strStart.length)];
        [attStr addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xff9933, 1) range:NSMakeRange(strStart.length, strEnd.length + 5)];
        _agreementLabel.attributedText = attStr;
      
    }

    
    return _agreementLabel;
}
     
- (LZPopAlertView *)passwordRecoveryPopView
{
    if (_passwordRecoveryPopView) {
        return _passwordRecoveryPopView;
    }
    
    _passwordRecoveryPopView = [[NSBundle mainBundle] loadNibNamed:@"LZPopAlertView" owner:self options:nil].lastObject;
    
    return _passwordRecoveryPopView;
}
     
@end
